<?php

namespace app\index\model;

use think\Model;

class News extends BaseModel
{
    public function getUrlAttr($value, $data)
    {
        return $value ? $value : "/news/".$data['id'];
    }

    public static function getRecommend()
    {
        return self::where('recommendswitch', 1)->order('createtime desc')->select();
    }

    public static function getNews($size = 10)
    {
        return self::where('onlineswitch', 1)->order('createtime desc')->paginate($size);
    }

    public static function getById($id)
    {
        return self::where('id', $id)->find();
    }

    public static function getPreId($id)
    {
        return self::where('id', '<', $id)->order('id desc')->value('id');
    }

    public static function getNextId($id)
    {
        return self::where('id', '>', $id)->order('id asc')->value('id');
    }
}
